from rest_framework import serializers
from manage.models.goods import Category, Goods, Specs, SpecsValue


# 分类数据表序列化器
class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = Category
        fields = '__all__'
        # 递归深度
        depth = 3

# 商品数据表序列化器
class GoodsSerializer(serializers.ModelSerializer):
    cate=CategorySerializer(read_only=True)
    class Meta:
        model = Goods
        fields = '__all__'


# 规格属性表序列化器
class SpecsSerializer(serializers.ModelSerializer):
    # 设置父表序列化器
    goods=GoodsSerializer(read_only=True)
    class Meta:
        model = Specs
        fields = '__all__'

# 规格属性值表序列化器
class SpecsValueSerializer(serializers.ModelSerializer):
    # 设置父表序列化器
    specs=SpecsSerializer(read_only=True)
    class Meta:
        model = SpecsValue
        fields = '__all__'